<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "gky_msg_document".
 *
 * @property integer $id
 * @property integer $msgid
 * @property string $filename
 * @property string $filepath
 */
class GkyMsgDocument extends \yii\db\ActiveRecord {

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'gky_msg_document';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['msgid'], 'integer'],
            [['filename', 'filepath'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'msgid' => 'Msgid',
            'filename' => 'Filename',
            'filepath' => 'Filepath',
        ];
    }

    public static function getDocumentList($msgid) {
        $list = GkyMsgDocument::find()
            ->where(['msgid' => $msgid])
            ->all();
        return $list;
    }

    /**
     * 保存多个文件
     *
     * @param $msgid
     * @param $filepaths
     */
    public static function saveList($msgid, $filepaths){
        foreach($filepaths as $filepath){
            $msgDoc = new GkyMsgDocument();
            $msgDoc->filepath = $filepath;
            $msgDoc->msgid = $msgid;
            $msgDoc->save();
        }

    }

}
